var e = require;
var t = module;
var n = exports;
var o =
        (this && this.__assign) ||
        function () {
            return (o =
                Object.assign ||
                function (e) {
                    for (var t, n = 1, o = arguments.length; n < o; n++)
                        for (var i in (t = arguments[n])) Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);
                    return e;
                }).apply(this, arguments);
        },
    i =
        (this && this.__awaiter) ||
        function (e, a, s, c) {
            return new (s = s || Promise)(function (n, t) {
                function o(e) {
                    try {
                        r(c.next(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function i(e) {
                    try {
                        r(c.throw(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function r(e) {
                    var t;
                    e.done
                        ? n(e.value)
                        : ((t = e.value) instanceof s
                              ? t
                              : new s(function (e) {
                                    e(t);
                                })
                          ).then(o, i);
                }
                r((c = c.apply(e, a || [])).next());
            });
        },
    s =
        (this && this.__generator) ||
        function (n, o) {
            var i,
                r,
                a,
                s = {
                    label: 0,
                    sent: function () {
                        if (1 & a[0]) throw a[1];
                        return a[1];
                    },
                    trys: [],
                    ops: []
                },
                e = {next: t(0), throw: t(1), return: t(2)};
            return (
                "function" == typeof Symbol &&
                    (e[Symbol.iterator] = function () {
                        return this;
                    }),
                e
            );
            function t(t) {
                return function (e) {
                    return (function (t) {
                        if (i) throw new TypeError("Generator is already executing.");
                        for (; s; )
                            try {
                                if (
                                    ((i = 1),
                                    r &&
                                        (a =
                                            2 & t[0]
                                                ? r.return
                                                : t[0]
                                                ? r.throw || ((a = r.return) && a.call(r), 0)
                                                : r.next) &&
                                        !(a = a.call(r, t[1])).done)
                                )
                                    return a;
                                switch (((r = 0), (t = a ? [2 & t[0], a.value] : t)[0])) {
                                    case 0:
                                    case 1:
                                        a = t;
                                        break;
                                    case 4:
                                        return s.label++, {value: t[1], done: !1};
                                    case 5:
                                        s.label++, (r = t[1]), (t = [0]);
                                        continue;
                                    case 7:
                                        (t = s.ops.pop()), s.trys.pop();
                                        continue;
                                    default:
                                        if (
                                            !(a = 0 < (a = s.trys).length && a[a.length - 1]) &&
                                            (6 === t[0] || 2 === t[0])
                                        ) {
                                            s = 0;
                                            continue;
                                        }
                                        if (3 === t[0] && (!a || (t[1] > a[0] && t[1] < a[3]))) {
                                            s.label = t[1];
                                            break;
                                        }
                                        if (6 === t[0] && s.label < a[1]) {
                                            (s.label = a[1]), (a = t);
                                            break;
                                        }
                                        if (a && s.label < a[2]) {
                                            (s.label = a[2]), s.ops.push(t);
                                            break;
                                        }
                                        a[2] && s.ops.pop(), s.trys.pop();
                                        continue;
                                }
                                t = o.call(n, s);
                            } catch (e) {
                                (t = [6, e]), (r = 0);
                            } finally {
                                i = a = 0;
                            }
                        if (5 & t[0]) throw t[1];
                        return {value: t[0] ? t[1] : void 0, done: !0};
                    })([t, e]);
                };
            }
        };
Object.defineProperty(n, "__esModule", {value: !0}), (n.ByteDancePlatform = void 0);
var c = e("index"),
    r = e("common"),
    l = e("const"),
    a = e("env"),
    u = e("events"),
    p = e("http"),
    h = e("user-data"),
    d = e("platform-const"),
    e =
        ((f.prototype.string = function () {
            return d.PlatformCode.Bytedance;
        }),
        (f.prototype.initSDK = function () {
            return i(this, void 0, Promise, function () {
                return s(this, function (e) {
                    switch ((1, e.label)) {
                        case 0:
                            return (
                                this.initByteDanceListener(),
                                this.initCommonSetting(),
                                this.initTga(),
                                this.initVideoRecorder(),
                                [4, zs_sdk.zs_network.init()]
                            );
                        case 1:
                            return e.sent(), this.uploadAdEvent("active", {}), [2];
                    }
                });
            });
        }),
        (f.prototype.initTga = function () {
            var e;
            a.env.mode === a.EnvMode.PROD &&
                ((e = new ThinkingAnalyticsAPI(d.TgaConfig)).setSuperProperties({
                    ver: a.env.version,
                    platfrom: this.string(),
                    game: a.env.game
                }),
                e.init(),
                h.userData.setUid(e.getDistinctId()),
                (this.ta = e));
        }),
        (f.prototype.isSwitchedInitd = function () {
            return this.switchesInitd;
        }),
        (f.prototype.initByteDanceListener = function () {
            var n = this;
            tt.onShow(function (e) {
                var t = Date.now();
                console.log(d.LogTag, "on show", t),
                    u.platformEvent.emit({onShow: !0, isSharing: n.isSharing}),
                    h.userData.syncLaunchOption(e),
                    n.isSharing || n.reenter(),
                    n.startStopRecordTimeout(Math.max(1e3, d.VIDEO_RECORD_LIMIT - n.m_nRecordT));
            }),
                tt.onHide(function () {
                    (n.onHideT = Date.now()),
                        console.log(d.LogTag, "on hide", n.onHideT),
                        u.platformEvent.emit({onHide: !0}),
                        n.clearStopRecordTimeout();
                }),
                tt.onError(function (e) {
                    a.env.mode !== a.EnvMode.PROD &&
                        tt.showModal({
                            title: e.message || "异常报错",
                            content: e.stack || e + "",
                            showCancel: !1,
                            confirmText: "好的"
                        });
                }),
                tt.canIUse("onMemoryWarning") &&
                    tt.onMemoryWarning(function () {
                        tt.triggerGC();
                    });
            var t = tt.getUpdateManager();
            t.onCheckForUpdate(function (e) {
                console.log(d.LogTag, "update checked, hasUpdate=" + e.hasUpdate);
            }),
                t.onUpdateFailed(function () {
                    console.log(d.LogTag, "update Failed");
                }),
                t.onUpdateReady(function () {
                    tt.showModal({
                        title: "更新提示",
                        content: "新版本已经准备好，是否重启小游戏？",
                        success: function (e) {
                            e.confirm && t.applyUpdate();
                        }
                    });
                });
        }),
        (f.prototype.initCommonSetting = function () {
            var t = this;
            h.userData.syncLaunchOption(tt.getLaunchOptionsSync()),
                tt.getNetworkType({
                    success: function (e) {
                        console.log("<<< byte dance getNetworkType success:", e), (h.userData.network = e);
                    },
                    fail: function (e) {
                        console.log("<<< byte dance getNetworkType fail:", e);
                    }
                }),
                u.cheatEvent.on(function (e) {
                    "noAd" == e
                        ? ((t.noAd = !t.noAd), c.showToast("分享视频直接成功" + t.noAd))
                        : "switchVideo" == e
                        ? ((t.noVideo = !t.noVideo), c.showToast("强制没有视频" + t.noVideo))
                        : "clearStorage" == e && t.clearStorage();
                });
        }),
        (f.prototype.setAccountID = function () {
            a.env.mode, a.EnvMode.TEST;
        }),
        (f.prototype.login = function () {
            return i(this, void 0, Promise, function () {
                return s(this, function () {
                    return [2, null];
                });
            });
        }),
        (f.prototype.reenter = function () {}),
        (f.prototype.getStorage = function (t) {
            try {
                return JSON.parse(tt.getStorageSync(t));
            } catch (e) {
                t = "";
                null != e && null != e.message && (t = e.message),
                    this.trackEvent("error", {type: "getStorage", message: t});
            }
        }),
        (f.prototype.setStorage = function (e, t) {
            try {
                tt.setStorageSync(e, JSON.stringify(t));
            } catch (e) {
                t = "";
                null != e && null != e.message && (t = e.message),
                    this.trackEvent("error", {type: "setStorage", message: t});
            }
        }),
        (f.prototype.clearStorage = function () {
            try {
                tt.clearStorageSync();
            } catch (e) {
                var t = "";
                null != e && null != e.message && (t = e.message),
                    this.trackEvent("error", {type: "cleanStorage", message: t});
            }
        }),
        (f.prototype.removeStorage = function (t) {
            try {
                tt.removeStorageSync(t);
            } catch (e) {
                t = "";
                null != e && null != e.message && (t = e.message),
                    this.trackEvent("error", {type: "removeStorage", message: t});
            }
        }),
        (f.prototype.trackLogin = function () {
            throw new Error("Method not implemented.");
        }),
        (f.prototype.trackUserSet = function (e) {
            null != this.ta && this.ta.userSet(e);
        }),
        (f.prototype.trackUserSetOnce = function (e) {
            null != e && null != this.ta && this.ta.userSetOnce(e);
        }),
        (f.prototype.trackEvent = function (e, t) {
            null != this.ta &&
                ((t = o({runTime: h.userData.enterAt ? (Date.now() - h.userData.enterAt) / 1e3 : 0}, t)),
                this.ta.track(e, t));
        }),
        (f.prototype.getSeq = function () {
            throw new Error("Method not implemented.");
        }),
        (f.prototype.consumeSeq = function (t) {
            return i(this, void 0, Promise, function () {
                return s(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return (
                                console.log(d.LogTag, "consume sequence", t),
                                t.sequenceInfo.type == d.STDSeqType.VIDEO ? [4, this.doWatchAD(t)] : [3, 2]
                            );
                        case 1:
                            return e.sent(), [3, 4];
                        case 2:
                            return [4, this.doShare(t)];
                        case 3:
                            e.sent(), (e.label = 4);
                        case 4:
                            return [2];
                    }
                });
            });
        }),
        (f.prototype.doWatchAD = function (a) {
            return i(this, void 0, Promise, function () {
                var i, r;
                return s(this, function () {
                    return this.noAd
                        ? [2]
                        : this.noVideo
                        ? [2, Promise.reject(d.VideoFailCode.NO_AD)]
                        : (u.adEvent.emit(l.AdEvent.VIDEO),
                          (i = this.uniqueVideoUnitId),
                          null == this.videoAd && (this.videoAd = tt.createRewardedVideoAd({adUnitId: i})),
                          this.showLoading(),
                          (r = this),
                          [
                              2,
                              new Promise(function (n, o) {
                                  r.videoAd.onClose(function e(t) {
                                      null != r.videoAd && r.videoAd.offClose(e),
                                          null != t && t.isEnded
                                              ? (u.adEvent.emit(l.AdEvent.VIDEO_END),
                                                r.trackEvent("video", {
                                                    step: "complete",
                                                    unit: i,
                                                    type: a.videoSource,
                                                    item: a.item
                                                }),
                                                (t = "video_" + h.userData.incVideoCnt().toString()),
                                                c.platform.uploadAdEvent_Addict(t),
                                                zs_sdk.zs_dyzt.checkVideoReport(!0),
                                                n())
                                              : (u.adEvent.emit(l.AdEvent.VIDEO_END),
                                                r.trackEvent("video", {
                                                    step: "cancel",
                                                    unit: i,
                                                    type: a.videoSource,
                                                    item: a.item
                                                }),
                                                zs_sdk.zs_dyzt.checkVideoReport(!1),
                                                o(d.VideoFailCode.CANCELED));
                                  }),
                                      r.videoAd
                                          .show()
                                          .then(function () {
                                              r.trackEvent("video", {
                                                  step: "display",
                                                  success: !0,
                                                  unit: i,
                                                  type: a.videoSource,
                                                  item: a.item
                                              }),
                                                  r.uploadAdEvent("active_pay", {});
                                          })
                                          .catch(function (e) {
                                              console.log("<<<< video err: ", e),
                                                  r.trackEvent("video", {
                                                      step: "display",
                                                      success: !1,
                                                      unit: i,
                                                      type: a.videoSource,
                                                      item: a.item
                                                  }),
                                                  u.adEvent.emit(l.AdEvent.VIDEO_END),
                                                  r.videoAd.destroy(),
                                                  (r.videoAd = null),
                                                  o(d.VideoFailCode.NO_AD);
                                          })
                                          .then(function () {
                                              r.hideLoading();
                                          });
                              })
                          ]);
                });
            });
        }),
        (f.prototype.doShare = function () {
            return i(this, void 0, Promise, function () {
                return s(this, function () {
                    throw new Error("Method not implemented.");
                });
            });
        }),
        (f.prototype._askReShare = function () {
            return i(this, void 0, Promise, function () {
                return s(this, function () {
                    return [
                        2,
                        new Promise(function (t) {
                            tt.showModal({
                                title: "提示",
                                content: "分享失败",
                                showCancel: !0,
                                cancelText: "取消",
                                confirmText: "去分享",
                                confirmColor: "#576B95",
                                success: function (e) {
                                    e.confirm ? t(!0) : e.cancel && t(!1);
                                },
                                fail: function () {
                                    t(!1);
                                }
                            });
                        })
                    ];
                });
            });
        }),
        (f.prototype.canUse = function (e) {
            return 0 <= r.compareVersion(this.getSystemData().SDKVersion, e);
        }),
        (f.prototype.getSystemData = function () {
            if (null == this.systemInfoCache)
                try {
                    this.systemInfoCache = tt.getSystemInfoSync();
                } catch (e) {
                    return d.DefaultSystemInfo;
                }
            return this.systemInfoCache;
        }),
        (f.prototype.getSwitches = function () {
            return this.sdkSwitch;
        }),
        (f.prototype.vibrate = function (e) {
            e == d.VibrateType.SHORT
                ? tt.vibrateShort({success: function () {}, fail: function () {}})
                : e == d.VibrateType.LONG && tt.vibrateLong({success: function () {}, fail: function () {}});
        }),
        (f.prototype.preloadVideo = function () {
            return !1;
        }),
        (f.prototype.showModal = function (e) {
            return new Promise(function (t) {
                tt.showModal(
                    o(o({}, e), {
                        success: function (e) {
                            e.confirm ? t(!0) : e.cancel && t(!1);
                        },
                        fail: function () {
                            t(!1);
                        }
                    })
                );
            });
        }),
        (f.prototype.refreshGame = function () {
            tt.exitMiniProgram();
        }),
        (f.prototype.showLoading = function () {
            this.canUse("1.0.0") && ((this.isLoading = !0), tt.showLoading({title: "加载中", mask: !0}));
        }),
        (f.prototype.hideLoading = function () {
            this.canUse("1.0.0") && this.isLoading && (tt.hideLoading(), (this.isLoading = !1));
        }),
        (f.prototype.log = function (e) {
            for (var t = [], n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
        }),
        (f.prototype.getMenuBounding = function () {
            var e, t, n, o;
            return (
                null == this.menuBounding &&
                    (this.canUse("2.1.0")
                        ? ((e = tt.getMenuButtonBoundingClientRect()),
                          (o = this.getSystemData()),
                          (n = (t = cc.view.getFrameSize()).width / o.screenWidth),
                          (o = t.height / o.screenHeight),
                          (this.menuBounding = cc.rect(e.left * n, e.top * o, e.width * n, e.height * o)))
                        : (this.menuBounding = new cc.Rect(650, 0, 100, 50))),
                this.menuBounding
            );
        }),
        (f.prototype.createShareImage = function () {
            return i(this, void 0, Promise, function () {
                return s(this, function () {
                    return [
                        2,
                        new Promise(function (e) {
                            e(null);
                        })
                    ];
                });
            });
        }),
        (f.prototype.preloadInterstitialAD = function () {}),
        (f.prototype.showInterstitialAD = function () {
            return i(this, void 0, Promise, function () {
                return s(this, function () {
                    return [2];
                });
            });
        }),
        (f.prototype.canShowBanner = function () {
            return !1;
        }),
        (f.prototype.getBannerSize = function () {
            return new cc.Size(0, 0);
        }),
        (f.prototype.showBanner = function () {
            cc.log("ByteDance does not support banner");
        }),
        (f.prototype.hideBanner = function () {
            cc.log("ByteDance does not support banner");
        }),
        (f.prototype.getSubscribeCnt = function () {
            return i(this, void 0, Promise, function () {
                return s(this, function () {
                    return [2, 0];
                });
            });
        }),
        (f.prototype.subscribe = function (e) {
            for (var t = [], n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
            return i(this, void 0, Promise, function () {
                return s(this, function () {
                    throw new Error("Method not implemented.");
                });
            });
        }),
        (f.prototype.initVideoRecorder = function () {
            this.canUse("1.6.1") &&
                ((this.gameRecorder = tt.getGameRecorderManager()),
                this.gameRecorder.onStart(this.onVideoRecordStart.bind(this)),
                this.gameRecorder.onStop(this.onVideoRecordEnd.bind(this)),
                this.gameRecorder.onError(this.onVideoRecordError.bind(this)));
        }),
        (f.prototype.startVideoRecord = function () {
            null != this.gameRecorder &&
                ((this.m_bIsRecording = !0),
                this.gameRecorder.start({duration: 0.001 * d.VIDEO_RECORD_LIMIT, isMarkOpen: !1}),
                this.startStopRecordTimeout(d.VIDEO_RECORD_LIMIT));
        }),
        (f.prototype.pauseVideoRecord = function () {
            null != this.gameRecorder &&
                this.m_bIsRecording &&
                (this.gameRecorder.pause(), this.clearStopRecordTimeout());
        }),
        (f.prototype.resumeVideoRecord = function () {
            null != this.gameRecorder &&
                this.m_bIsRecording &&
                (this.gameRecorder.resume(),
                this.startStopRecordTimeout(Math.max(1e3, d.VIDEO_RECORD_LIMIT - this.m_nRecordT)));
        }),
        (f.prototype.stopVideoRecord = function () {
            null != this.gameRecorder &&
                (this.clearStopRecordTimeout(), this.gameRecorder.stop(), (this.m_bIsRecording = !1));
        }),
        (f.prototype.startStopRecordTimeout = function (e) {
            this.m_bIsRecording &&
                ((this.m_nAutoStopVideoId = setTimeout(this.autoStopVideoRecord.bind(this), e - 1e3)),
                (this.m_nStartRecordT = new Date().getTime()));
        }),
        (f.prototype.clearStopRecordTimeout = function () {
            this.m_bIsRecording &&
                (0 !== this.m_nAutoStopVideoId && clearTimeout(this.m_nAutoStopVideoId),
                (this.m_nAutoStopVideoId = 0),
                (this.m_nRecordT += new Date().getTime() - this.m_nStartRecordT),
                (this.m_nStartRecordT = 0));
        }),
        (f.prototype.autoStopVideoRecord = function () {
            (this.m_nAutoStopVideoId = 0), this.stopVideoRecord(), setTimeout(this.startVideoRecord.bind(this), 100);
        }),
        (f.prototype.onVideoRecordStart = function () {
            (this.m_strVideoPath = ""), (this.m_nRecordT = 0);
        }),
        (f.prototype.onVideoRecordEnd = function (e) {
            null != e && null != e.videoPath && (this.m_strVideoPath = e.videoPath);
        }),
        (f.prototype.onVideoRecordError = function () {}),
        (f.prototype.hasVideoRecord = function () {
            return null != this.m_strVideoPath && "" !== this.m_strVideoPath;
        }),
        (f.prototype.shareVideoRecord = function (t, e, n, o) {
            var i, r;
            this.hasVideoRecord() &&
                ((i = this),
                (r = [a.env.name, "脑洞游戏", "烧脑益智"]),
                tt.shareAppMessage({
                    title: a.env.name,
                    channel: "video",
                    desc: "来挑战一下",
                    query: "lvl=" + t.toString() + "&code=" + e,
                    extra: {
                        withVideoId: !0,
                        videoPath: this.m_strVideoPath,
                        video_title: "太难了",
                        videoTopics: r,
                        hashtag_list: r,
                        videoTag: "coin_raddle_record"
                    },
                    success: function (e) {
                        console.log("<<<< 分享录频成功", e),
                            i.trackEvent("share_record", {level: t, name: n, success: !0, item: o});
                    },
                    fail: function (e) {
                        console.log("<<<< 分享录频失败", e),
                            i.trackEvent("share_record", {level: t, name: n, success: !1, item: o});
                    }
                }));
        }),
        (f.prototype.uploadAdEvent = function (e, t) {
            var n = h.userData.getLocalDataByKey("register_date");
            if (!(null != n && 108e5 <= new Date().getTime() - n)) {
                n = h.userData.getLocalDataByKey("clickid");
                if (null != n)
                    try {
                        p.makeRequest("post", "https://analytics.oceanengine.com/api/v2/conversion", {
                            parameters: {},
                            body: {
                                event_type: e,
                                context: {ad: {callback: n, match_type: 3}},
                                properties: t,
                                timestamp: new Date().getTime()
                            },
                            maxAutoRetryCnt: 1,
                            silence: !0
                        });
                    } catch (e) {}
            }
        }),
        (f.prototype.uploadAdEvent_Addict = function (e) {
            var t = h.userData.getLocalDataByKey("addict_type");
            (t = null == t ? d.GameAddictType.Start_Lvl : t) === e && this.uploadAdEvent("game_addiction", {});
        }),
        (f.prototype.addShortcut = function () {
            tt.addShortcut({
                success: function () {
                    c.platform.trackEvent("clickAddDeck", {bool: !0}), console.log("success");
                },
                fail: function () {
                    c.platform.trackEvent("clickAddDeck", {bool: !1}), c.showToast("添加失败", 1500);
                }
            });
        }),
        f);
function f() {
    (this.isSharing = !1),
        (this.sdkSwitch = d.DefaultSDKSwitch),
        (this.videoCheckedMap = {}),
        (this.videoCheckedLastT = {}),
        (this.uniqueVideoUnitId = "70qb1fhg9s84aclnac"),
        (this.isLoading = !1),
        (this.isLoggedIn = !1),
        (this.onHideT = 0),
        (this.noAd = !1),
        (this.noVideo = !1),
        (this.lastInterAdShowT = 0),
        (this.switchesInitd = !1),
        (this.gameRecorder = null),
        (this.ta = null),
        (this.m_nStartRecordT = 0),
        (this.m_nRecordT = 0),
        (this.m_bIsRecording = !1),
        (this.m_nAutoStopVideoId = 0),
        (this.m_strVideoPath = "");
}
n.ByteDancePlatform = e;
